from django.db import models

# Create your models here.

class BaseModel(models.Model):
    """为模型类补充字段"""

    create_time = models.DateTimeField(auto_now_add=True, verbose_name="创建时间")
    update_time = models.DateTimeField(auto_now=True, verbose_name="更新时间")

    class Meta:
        abstract = True  # 说明是抽象模型类, 用于继承使用，数据库迁移时不会创建BaseModel的表
class Area(models.Model):
    """省市区"""
    name = models.CharField(max_length=20, verbose_name='名称')
    parent = models.ForeignKey('self', on_delete=models.SET_NULL, related_name='subs', null=True, blank=True, verbose_name='上级行政区划',default=None)

    class Meta:
        db_table = 'tb_areas'
    def __str__(self):
        return self.name

class HouseInfo(BaseModel):
    jiedao_name = models.ForeignKey(Area,on_delete=models.SET_NULL,null=True)
    house_name = models.CharField(max_length=500, verbose_name='名称')
    image_url = models.CharField(max_length=500, verbose_name='图片链接')
    # 链接详情页链接
    detail_url = models.CharField(max_length=500, verbose_name='小区详情页')
    # 小区名字
    village_name = models.CharField(max_length=500, verbose_name='小区名字')
    house_layout = models.CharField(max_length=20, verbose_name='户型')
    house_space = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='面积')
    total_price = models.DecimalField(max_digits=10,decimal_places=2,verbose_name='总价')
    unit_price = models.DecimalField(max_digits=10,decimal_places=2, verbose_name='单价')
